//package com.cc.controller;
//
//import com.cc.config.UpdateDataBaseConfig;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.cloud.context.refresh.ContextRefresher;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RestController;
//import org.yaml.snakeyaml.Yaml;
//
//import java.io.FileInputStream;
//import java.io.*;
//import java.io.IOException;
//import java.util.Map;
//
///**
// * @author tj
// * @apiNote
// * @date 2021/8/30
// */
//@RestController
//public class  ResfultController{
//
//  @Qualifier("legacyContextRefresher")
//  @Autowired(required = true)
//  private ContextRefresher contextRefresher;
//
//  @Autowired
//  private UpdateDataBaseConfig esConfig;
//
//  @GetMapping("/api/refresh/{value}")
//  public void refresh(@PathVariable String value) throws IOException {
//    // 修改配置文件
//    updateYamlFile(value);
//    // 刷新配置文件
//    //contextRefresher.refresh();
//    // 使用刷新后的配置
////    System.out.print(esConfig.getPassword());
//  }
//
//  public void updateYamlFile(String value) throws IOException {
//    String src = ResfultController.class.getClassLoader().getResource("application.yml").getPath();
//    //String src = "src/main/resources/application.yml";
//    Yaml yaml = new Yaml();
//    FileWriter fileWriter;
//    FileInputStream fileInputStream = new FileInputStream(new File(src));
//    Map<String, Object> yamlMap = yaml.load(fileInputStream);
//    Map<String, Object> esMap = (Map<String, Object>) yamlMap.get("elasticsearch");
//    esMap.put("password", value);
//    //字符输出
//    fileWriter = new FileWriter(new File(src));
//    //用yaml方法把map结构格式化为yaml文件结构
//    fileWriter.write(yaml.dumpAsMap(yamlMap));
//    //刷新
//    fileWriter.flush();
//    //关闭流
//    fileWriter.close();
//    fileInputStream.close();
//    new Thread(() ->contextRefresher.refresh()).start();
//  }
//}